home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 10.May.2002
- //
- //<doc>
- //<name getApplicationVersionAsFloat>
- //<owner "Alias|Wavefront">
- //
- //<synopsis>
- // getApplicationVersionAsFloat()
- //
- //<returns>
- // float : Value containing the major and minor version numbers.
- //
- //<description>
- // Return the application version number as a float value.
- // <p>
- // If you use the "about -version" command you get a string
- // value containing the application version. Strings of course
- // may not be used in comparisons like:
- // <p>
- // if ($version > 3.5) { ... };
- // <p>
- // This procedure will return a float value containing the
- // major and minor version number. The major version will be
- // separated from the minor version by a decimal. For example,
- // 4.0.3 will return a float value of 4.03.
- //
- //<examples>
- // if (getApplicationVersionAsFloat() >= 2.5) {
- // print ("Running version 2.5 or higher\n");
- // };
- //
- //</doc>
- //
- global proc float getApplicationVersionAsFloat()
- {
- float $version = 0.0;
- string $result;
- string $versionString = `about -version`;
-
- // The following regular expression will ensure a string begins
- // with a digit and strip out any non-numeric characters. You will be
- // left with a result that looks like the following (where N is
- // one more digits).
- //
- // N
- // N.N
- // N.N.N
- // N.N.N.N
- //
- string $regularExpression = "^[0-9]+[.]*[0-9]*[.]*[0-9]*[.]*[0-9]*";
- $result = `match $regularExpression $versionString`;
- if ("" != $result) {
- //
- // Determine the major, minor and patch numbers by tokenizing
- // the string with the period character.
- //
- // The first token will become the whole value left of the
- // decimal point. The remaing tokens will be appended together
- // to form the fractional part to the right of the decimal.
- //
- // For example, N.N.N.N will become N.NNN.
- //
- string $tokenArray[];
- int $tokenCount;
- $tokenCount= `tokenize $result "." $tokenArray`;
- $result = "";
- for ($index = 0; $index < $tokenCount; $index++) {
- $result += $tokenArray[$index];
- if ($index == 0 && $tokenCount > 1) {
- $result += ".";
- }
- }
- $version = $result;
- }
-
- return $version;
- }
-